
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.io.abinit.abiobjects &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
    <script src="../../../../_static/jquery.js"></script>
    <script src="../../../../_static/underscore.js"></script>
    <script src="../../../../_static/doctools.js"></script>
    <script src="../../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.io.abinit.abiobjects</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.io.abinit.abiobjects</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Low-level objects providing an abstraction for the objects involved in the calculation.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">collections</span>
<span class="kn">import</span> <span class="nn">abc</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pymatgen.core.units</span> <span class="k">as</span> <span class="nn">units</span>

<span class="kn">from</span> <span class="nn">pprint</span> <span class="kn">import</span> <span class="n">pformat</span>
<span class="kn">from</span> <span class="nn">monty.design_patterns</span> <span class="kn">import</span> <span class="n">singleton</span>
<span class="kn">from</span> <span class="nn">monty.collections</span> <span class="kn">import</span> <span class="n">AttrDict</span>
<span class="kn">from</span> <span class="nn">enum</span> <span class="kn">import</span> <span class="n">Enum</span>
<span class="kn">from</span> <span class="nn">monty.json</span> <span class="kn">import</span> <span class="n">MSONable</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.units</span> <span class="kn">import</span> <span class="n">ArrayWithUnit</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.lattice</span> <span class="kn">import</span> <span class="n">Lattice</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.structure</span> <span class="kn">import</span> <span class="n">Structure</span>
<span class="kn">from</span> <span class="nn">pymatgen.util.serialization</span> <span class="kn">import</span> <span class="n">pmg_serialize</span>
<span class="kn">from</span> <span class="nn">pymatgen.symmetry.analyzer</span> <span class="kn">import</span> <span class="n">SpacegroupAnalyzer</span>
<span class="kn">from</span> <span class="nn">monty.json</span> <span class="kn">import</span> <span class="n">MontyEncoder</span><span class="p">,</span> <span class="n">MontyDecoder</span>


<div class="viewcode-block" id="lattice_from_abivars"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.lattice_from_abivars">[docs]</a><span class="k">def</span> <span class="nf">lattice_from_abivars</span><span class="p">(</span><span class="bp">cls</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Returns a `Lattice` object from a dictionary</span>
<span class="sd">    with the Abinit variables `acell` and either `rprim` in Bohr or `angdeg`</span>
<span class="sd">    If acell is not given, the Abinit default is used i.e. [1,1,1] Bohr</span>

<span class="sd">    Args:</span>
<span class="sd">        cls: Lattice class to be instantiated. pymatgen.core.lattice.Lattice if `cls` is None</span>

<span class="sd">    Example:</span>

<span class="sd">        lattice_from_abivars(acell=3*[10], rprim=np.eye(3))</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">cls</span> <span class="o">=</span> <span class="n">Lattice</span> <span class="k">if</span> <span class="bp">cls</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="bp">cls</span>
    <span class="n">kwargs</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="nb">dict</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">))</span>
    <span class="n">d</span> <span class="o">=</span> <span class="n">kwargs</span>

    <span class="n">rprim</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;rprim&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
    <span class="n">angdeg</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;angdeg&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
    <span class="n">acell</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;acell&quot;</span><span class="p">]</span>

    <span class="k">if</span> <span class="n">rprim</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">angdeg</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;angdeg and rprimd are mutually exclusive&quot;</span><span class="p">)</span>
        <span class="n">rprim</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">rprim</span><span class="p">,</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
        <span class="n">rprimd</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">acell</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">*</span> <span class="n">rprim</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">)]</span>
        <span class="c1"># Call pymatgen constructors (note that pymatgen uses Angstrom instead of Bohr).</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">ArrayWithUnit</span><span class="p">(</span><span class="n">rprimd</span><span class="p">,</span> <span class="s2">&quot;bohr&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;ang&quot;</span><span class="p">))</span>

    <span class="k">elif</span> <span class="n">angdeg</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
        <span class="n">angdeg</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">angdeg</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">any</span><span class="p">(</span><span class="n">angdeg</span> <span class="o">&lt;=</span> <span class="mf">0.</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Angles must be &gt; 0 but got </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="nb">str</span><span class="p">(</span><span class="n">angdeg</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">angdeg</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span> <span class="o">&gt;=</span> <span class="mf">360.</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;The sum of angdeg must be lower that 360, angdeg </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="nb">str</span><span class="p">(</span><span class="n">angdeg</span><span class="p">))</span>

        <span class="c1"># This code follows the implementation in ingeo.F90</span>
        <span class="c1"># See also http://www.abinit.org/doc/helpfiles/for-v7.8/input_variables/varbas.html#angdeg</span>
        <span class="n">tol12</span> <span class="o">=</span> <span class="mf">1e-12</span>
        <span class="n">pi</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">sqrt</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span>
        <span class="n">rprim</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
        <span class="k">if</span> <span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">angdeg</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">angdeg</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">&lt;</span> <span class="n">tol12</span> <span class="ow">and</span> <span class="nb">abs</span><span class="p">(</span><span class="n">angdeg</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">angdeg</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="o">&lt;</span> <span class="n">tol12</span> <span class="ow">and</span>
                <span class="nb">abs</span><span class="p">(</span><span class="n">angdeg</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="mf">90.</span><span class="p">)</span> <span class="o">+</span> <span class="nb">abs</span><span class="p">(</span><span class="n">angdeg</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="mf">90.</span><span class="p">)</span> <span class="o">+</span> <span class="nb">abs</span><span class="p">(</span><span class="n">angdeg</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">-</span> <span class="mi">90</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">tol12</span><span class="p">):</span>
            <span class="c1"># Treat the case of equal angles (except all right angles):</span>
            <span class="c1"># generates trigonal symmetry wrt third axis</span>
            <span class="n">cosang</span> <span class="o">=</span> <span class="n">cos</span><span class="p">(</span><span class="n">pi</span> <span class="o">*</span> <span class="n">angdeg</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/</span> <span class="mf">180.0</span><span class="p">)</span>
            <span class="n">a2</span> <span class="o">=</span> <span class="mf">2.0</span> <span class="o">/</span> <span class="mf">3.0</span> <span class="o">*</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">cosang</span><span class="p">)</span>
            <span class="n">aa</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">a2</span><span class="p">)</span>
            <span class="n">cc</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">a2</span><span class="p">)</span>
            <span class="n">rprim</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">aa</span>
            <span class="n">rprim</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.0</span>
            <span class="n">rprim</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">cc</span>
            <span class="n">rprim</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="mf">0.5</span> <span class="o">*</span> <span class="n">aa</span>
            <span class="n">rprim</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="mf">3.0</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="n">aa</span>
            <span class="n">rprim</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">cc</span>
            <span class="n">rprim</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="mf">0.5</span> <span class="o">*</span> <span class="n">aa</span>
            <span class="n">rprim</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="n">sqrt</span><span class="p">(</span><span class="mf">3.0</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="n">aa</span>
            <span class="n">rprim</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">cc</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># Treat all the other cases</span>
            <span class="n">rprim</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mf">1.0</span>
            <span class="n">rprim</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">cos</span><span class="p">(</span><span class="n">pi</span> <span class="o">*</span> <span class="n">angdeg</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">/</span> <span class="mf">180.</span><span class="p">)</span>
            <span class="n">rprim</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">sin</span><span class="p">(</span><span class="n">pi</span> <span class="o">*</span> <span class="n">angdeg</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">/</span> <span class="mf">180.</span><span class="p">)</span>
            <span class="n">rprim</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">cos</span><span class="p">(</span><span class="n">pi</span> <span class="o">*</span> <span class="n">angdeg</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">/</span> <span class="mf">180.</span><span class="p">)</span>
            <span class="n">rprim</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">cos</span><span class="p">(</span><span class="n">pi</span> <span class="o">*</span> <span class="n">angdeg</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/</span> <span class="mf">180.0</span><span class="p">)</span> <span class="o">-</span> <span class="n">rprim</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">rprim</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span> <span class="o">/</span> <span class="n">rprim</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span>
            <span class="n">rprim</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">rprim</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">-</span> <span class="n">rprim</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span>

        <span class="c1"># Call pymatgen constructors (note that pymatgen uses Angstrom instead of Bohr).</span>
        <span class="n">rprimd</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">acell</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">*</span> <span class="n">rprim</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">)]</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">ArrayWithUnit</span><span class="p">(</span><span class="n">rprimd</span><span class="p">,</span> <span class="s2">&quot;bohr&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;ang&quot;</span><span class="p">))</span>

    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Don&#39;t know how to construct a Lattice from dict:</span><span class="se">\n</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">pformat</span><span class="p">(</span><span class="n">d</span><span class="p">))</span></div>


<div class="viewcode-block" id="structure_from_abivars"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.structure_from_abivars">[docs]</a><span class="k">def</span> <span class="nf">structure_from_abivars</span><span class="p">(</span><span class="bp">cls</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Build a :class:`Structure` object from a dictionary with ABINIT variables.</span>

<span class="sd">    Args:</span>
<span class="sd">        cls: Structure class to be instantiated. pymatgen.core.structure.Structure if cls is None</span>

<span class="sd">    example:</span>

<span class="sd">        al_structure = structure_from_abivars(</span>
<span class="sd">            acell=3*[7.5],</span>
<span class="sd">            rprim=[0.0, 0.5, 0.5,</span>
<span class="sd">                   0.5, 0.0, 0.5,</span>
<span class="sd">                   0.5, 0.5, 0.0],</span>
<span class="sd">            typat=1,</span>
<span class="sd">            xred=[0.0, 0.0, 0.0],</span>
<span class="sd">            ntypat=1,</span>
<span class="sd">            znucl=13,</span>
<span class="sd">        )</span>

<span class="sd">    `xred` can be replaced with `xcart` or `xangst`.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">kwargs</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="nb">dict</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">))</span>
    <span class="n">d</span> <span class="o">=</span> <span class="n">kwargs</span>

    <span class="bp">cls</span> <span class="o">=</span> <span class="n">Structure</span> <span class="k">if</span> <span class="bp">cls</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="bp">cls</span>

    <span class="c1"># lattice = Lattice.from_dict(d, fmt=&quot;abivars&quot;)</span>
    <span class="n">lattice</span> <span class="o">=</span> <span class="n">lattice_from_abivars</span><span class="p">(</span><span class="o">**</span><span class="n">d</span><span class="p">)</span>
    <span class="n">coords</span><span class="p">,</span> <span class="n">coords_are_cartesian</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;xred&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span> <span class="kc">False</span>

    <span class="k">if</span> <span class="n">coords</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="n">coords</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;xcart&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">coords</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="s2">&quot;xangst&quot;</span> <span class="ow">in</span> <span class="n">d</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;xangst and xcart are mutually exclusive&quot;</span><span class="p">)</span>
            <span class="n">coords</span> <span class="o">=</span> <span class="n">ArrayWithUnit</span><span class="p">(</span><span class="n">coords</span><span class="p">,</span> <span class="s2">&quot;bohr&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;ang&quot;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">coords</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;xangst&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">coords_are_cartesian</span> <span class="o">=</span> <span class="kc">True</span>

    <span class="k">if</span> <span class="n">coords</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Cannot extract coordinates from:</span><span class="se">\n</span><span class="s2"> </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="nb">str</span><span class="p">(</span><span class="n">d</span><span class="p">))</span>

    <span class="n">coords</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">coords</span><span class="p">,</span> <span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>

    <span class="n">znucl_type</span><span class="p">,</span> <span class="n">typat</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;znucl&quot;</span><span class="p">],</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;typat&quot;</span><span class="p">]</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">znucl_type</span><span class="p">,</span> <span class="n">collections</span><span class="o">.</span><span class="n">abc</span><span class="o">.</span><span class="n">Iterable</span><span class="p">):</span>
        <span class="n">znucl_type</span> <span class="o">=</span> <span class="p">[</span><span class="n">znucl_type</span><span class="p">]</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">typat</span><span class="p">,</span> <span class="n">collections</span><span class="o">.</span><span class="n">abc</span><span class="o">.</span><span class="n">Iterable</span><span class="p">):</span>
        <span class="n">typat</span> <span class="o">=</span> <span class="p">[</span><span class="n">typat</span><span class="p">]</span>

    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">typat</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">coords</span><span class="p">):</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;len(typat) != len(coords):</span><span class="se">\n</span><span class="s2">typat: </span><span class="si">%s</span><span class="se">\n</span><span class="s2">coords: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">typat</span><span class="p">,</span> <span class="n">coords</span><span class="p">))</span>

    <span class="c1"># Note conversion to int and Fortran --&gt; C indexing</span>
    <span class="n">typat</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">typat</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">int</span><span class="p">)</span>
    <span class="n">species</span> <span class="o">=</span> <span class="p">[</span><span class="n">znucl_type</span><span class="p">[</span><span class="n">typ</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">typ</span> <span class="ow">in</span> <span class="n">typat</span><span class="p">]</span>

    <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">lattice</span><span class="p">,</span> <span class="n">species</span><span class="p">,</span> <span class="n">coords</span><span class="p">,</span> <span class="n">validate_proximity</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
               <span class="n">to_unit_cell</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="n">coords_are_cartesian</span><span class="p">)</span></div>


<div class="viewcode-block" id="structure_to_abivars"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.structure_to_abivars">[docs]</a><span class="k">def</span> <span class="nf">structure_to_abivars</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Receives a structure and returns a dictionary with the ABINIT variables.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">structure</span><span class="o">.</span><span class="n">is_ordered</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;</span><span class="se">\</span>
<span class="s2">Received disordered structure with partial occupancies that cannot be converted into an Abinit input</span>
<span class="s2">Please use OrderDisorderedStructureTransformation or EnumerateStructureTransformation</span>
<span class="s2">to build an appropriate supercell from partial occupancies or alternatively use the Virtual Crystal Approximation.&quot;&quot;&quot;</span><span class="p">)</span>

    <span class="n">types_of_specie</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">types_of_specie</span>
    <span class="n">natom</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">num_sites</span>

    <span class="n">znucl_type</span> <span class="o">=</span> <span class="p">[</span><span class="n">specie</span><span class="o">.</span><span class="n">number</span> <span class="k">for</span> <span class="n">specie</span> <span class="ow">in</span> <span class="n">types_of_specie</span><span class="p">]</span>
    <span class="n">znucl_atoms</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">atomic_numbers</span>

    <span class="n">typat</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">natom</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">int</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">atm_idx</span><span class="p">,</span> <span class="n">site</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">structure</span><span class="p">):</span>
        <span class="n">typat</span><span class="p">[</span><span class="n">atm_idx</span><span class="p">]</span> <span class="o">=</span> <span class="n">types_of_specie</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span>

    <span class="n">rprim</span> <span class="o">=</span> <span class="n">ArrayWithUnit</span><span class="p">(</span><span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">matrix</span><span class="p">,</span> <span class="s2">&quot;ang&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;bohr&quot;</span><span class="p">)</span>
    <span class="n">angdeg</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">angles</span>
    <span class="n">xred</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">([</span><span class="n">site</span><span class="o">.</span><span class="n">frac_coords</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="n">structure</span><span class="p">],</span> <span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>

    <span class="c1"># Set small values to zero. This usually happens when the CIF file</span>
    <span class="c1"># does not give structure parameters with enough digits.</span>
    <span class="n">rprim</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">rprim</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mf">1e-8</span><span class="p">,</span> <span class="n">rprim</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">)</span>
    <span class="n">xred</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">xred</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mf">1e-8</span><span class="p">,</span> <span class="n">xred</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">)</span>

    <span class="c1"># Info on atoms.</span>
    <span class="n">d</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span>
        <span class="n">natom</span><span class="o">=</span><span class="n">natom</span><span class="p">,</span>
        <span class="n">ntypat</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">types_of_specie</span><span class="p">),</span>
        <span class="n">typat</span><span class="o">=</span><span class="n">typat</span><span class="p">,</span>
        <span class="n">znucl</span><span class="o">=</span><span class="n">znucl_type</span><span class="p">,</span>
        <span class="n">xred</span><span class="o">=</span><span class="n">xred</span><span class="p">,</span>
    <span class="p">)</span>

    <span class="c1"># Add info on the lattice.</span>
    <span class="c1"># Should we use (rprim, acell) or (angdeg, acell) to specify the lattice?</span>
    <span class="n">geomode</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;geomode&quot;</span><span class="p">,</span> <span class="s2">&quot;rprim&quot;</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">geomode</span> <span class="o">==</span> <span class="s2">&quot;automatic&quot;</span><span class="p">:</span>
        <span class="n">geomode</span> <span class="o">=</span> <span class="s2">&quot;rprim&quot;</span>
        <span class="k">if</span> <span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">is_hexagonal</span><span class="p">:</span>  <span class="c1"># or structure.lattice.is_rhombohedral</span>
            <span class="n">geomode</span> <span class="o">=</span> <span class="s2">&quot;angdeg&quot;</span>
            <span class="n">angdeg</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">angles</span>
            <span class="c1"># Here one could polish a bit the numerical values if they are not exact.</span>
            <span class="c1"># Note that in pmg the angles are 12, 20, 01 while in Abinit 12, 02, 01</span>
            <span class="c1"># One should make sure that the orientation is preserved (see Curtarolo&#39;s settings)</span>

    <span class="k">if</span> <span class="n">geomode</span> <span class="o">==</span> <span class="s2">&quot;rprim&quot;</span><span class="p">:</span>
        <span class="n">d</span><span class="o">.</span><span class="n">update</span><span class="p">(</span>
            <span class="n">acell</span><span class="o">=</span><span class="mi">3</span> <span class="o">*</span> <span class="p">[</span><span class="mf">1.0</span><span class="p">],</span>
            <span class="n">rprim</span><span class="o">=</span><span class="n">rprim</span><span class="p">,</span>
        <span class="p">)</span>

    <span class="k">elif</span> <span class="n">geomode</span> <span class="o">==</span> <span class="s2">&quot;angdeg&quot;</span><span class="p">:</span>
        <span class="n">d</span><span class="o">.</span><span class="n">update</span><span class="p">(</span>
            <span class="n">acell</span><span class="o">=</span><span class="n">ArrayWithUnit</span><span class="p">(</span><span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">abc</span><span class="p">,</span> <span class="s2">&quot;ang&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;bohr&quot;</span><span class="p">),</span>
            <span class="n">angdeg</span><span class="o">=</span><span class="n">angdeg</span><span class="p">,</span>
        <span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Wrong value for geomode: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">geomode</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">d</span></div>


<div class="viewcode-block" id="contract"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.contract">[docs]</a><span class="k">def</span> <span class="nf">contract</span><span class="p">(</span><span class="n">s</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    &gt;&gt;&gt; assert contract(&quot;1 1 1 2 2 3&quot;) == &quot;3*1 2*2 1*3&quot;</span>
<span class="sd">    &gt;&gt;&gt; assert contract(&quot;1 1 3 2 3&quot;) == &quot;2*1 1*3 1*2 1*3&quot;</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">s</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">s</span>

    <span class="n">tokens</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
    <span class="n">old</span> <span class="o">=</span> <span class="n">tokens</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
    <span class="n">count</span> <span class="o">=</span> <span class="p">[[</span><span class="mi">1</span><span class="p">,</span> <span class="n">old</span><span class="p">]]</span>

    <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">tokens</span><span class="p">[</span><span class="mi">1</span><span class="p">:]:</span>
        <span class="k">if</span> <span class="n">t</span> <span class="o">==</span> <span class="n">old</span><span class="p">:</span>
            <span class="n">count</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">old</span> <span class="o">=</span> <span class="n">t</span>
            <span class="n">count</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="n">t</span><span class="p">])</span>

    <span class="k">return</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%d</span><span class="s2">*</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">c</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span><span class="p">,</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">count</span><span class="p">)</span></div>


<div class="viewcode-block" id="AbivarAble"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.AbivarAble">[docs]</a><span class="k">class</span> <span class="nc">AbivarAble</span><span class="p">(</span><span class="n">metaclass</span><span class="o">=</span><span class="n">abc</span><span class="o">.</span><span class="n">ABCMeta</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    An `AbivarAble` object provides a method `to_abivars`</span>
<span class="sd">    that returns a dictionary with the abinit variables.</span>
<span class="sd">    &quot;&quot;&quot;</span>

<div class="viewcode-block" id="AbivarAble.to_abivars"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.AbivarAble.to_abivars">[docs]</a>    <span class="nd">@abc</span><span class="o">.</span><span class="n">abstractmethod</span>
    <span class="k">def</span> <span class="nf">to_abivars</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Returns a dictionary with the abinit variables.&quot;&quot;&quot;</span></div>

    <span class="c1"># @abc.abstractmethod</span>
    <span class="c1"># def from_abivars(cls, vars):</span>
    <span class="c1">#    &quot;&quot;&quot;Build the object from a dictionary with Abinit variables.&quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">pformat</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">to_abivars</span><span class="p">(),</span> <span class="n">indent</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">80</span><span class="p">,</span> <span class="n">depth</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__contains__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">key</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">to_abivars</span><span class="p">()</span></div>


<span class="nd">@singleton</span>
<span class="k">class</span> <span class="nc">MandatoryVariable</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Singleton used to tag mandatory variables, just because I can use</span>
<span class="sd">    the cool syntax: variable is MANDATORY!</span>
<span class="sd">    &quot;&quot;&quot;</span>


<span class="nd">@singleton</span>
<span class="k">class</span> <span class="nc">DefaultVariable</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;Singleton used to tag variables that will have the default value&quot;&quot;&quot;</span>


<span class="n">MANDATORY</span> <span class="o">=</span> <span class="n">MandatoryVariable</span><span class="p">()</span>
<span class="n">DEFAULT</span> <span class="o">=</span> <span class="n">DefaultVariable</span><span class="p">()</span>


<div class="viewcode-block" id="SpinMode"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.SpinMode">[docs]</a><span class="k">class</span> <span class="nc">SpinMode</span><span class="p">(</span><span class="n">collections</span><span class="o">.</span><span class="n">namedtuple</span><span class="p">(</span><span class="s1">&#39;SpinMode&#39;</span><span class="p">,</span> <span class="s2">&quot;mode nsppol nspinor nspden&quot;</span><span class="p">),</span> <span class="n">AbivarAble</span><span class="p">,</span> <span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Different configurations of the electron density as implemented in abinit:</span>
<span class="sd">    One can use as_spinmode to construct the object via SpinMode.as_spinmode</span>
<span class="sd">    (string) where string can assume the values:</span>

<span class="sd">        - polarized</span>
<span class="sd">        - unpolarized</span>
<span class="sd">        - afm (anti-ferromagnetic)</span>
<span class="sd">        - spinor (non-collinear magnetism)</span>
<span class="sd">        - spinor_nomag (non-collinear, no magnetism)</span>
<span class="sd">    &quot;&quot;&quot;</span>

<div class="viewcode-block" id="SpinMode.as_spinmode"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.SpinMode.as_spinmode">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">as_spinmode</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Converts obj into a `SpinMode` instance&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="bp">cls</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">obj</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># Assume a string with mode</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">_mode2spinvars</span><span class="p">[</span><span class="n">obj</span><span class="p">]</span>
            <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">KeyError</span><span class="p">(</span><span class="s2">&quot;Wrong value for spin_mode: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="nb">str</span><span class="p">(</span><span class="n">obj</span><span class="p">))</span></div>

<div class="viewcode-block" id="SpinMode.to_abivars"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.SpinMode.to_abivars">[docs]</a>    <span class="k">def</span> <span class="nf">to_abivars</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">{</span>
            <span class="s2">&quot;nsppol&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">nsppol</span><span class="p">,</span>
            <span class="s2">&quot;nspinor&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">nspinor</span><span class="p">,</span>
            <span class="s2">&quot;nspden&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">nspden</span><span class="p">,</span>
        <span class="p">}</span></div>

<div class="viewcode-block" id="SpinMode.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.SpinMode.as_dict">[docs]</a>    <span class="nd">@pmg_serialize</span>
    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fields</span><span class="p">}</span></div>

<div class="viewcode-block" id="SpinMode.from_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.SpinMode.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="o">**</span><span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">d</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">d</span> <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">cls</span><span class="o">.</span><span class="n">_fields</span><span class="p">})</span></div></div>


<span class="c1"># An handy Multiton</span>
<span class="n">_mode2spinvars</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s2">&quot;unpolarized&quot;</span><span class="p">:</span> <span class="n">SpinMode</span><span class="p">(</span><span class="s2">&quot;unpolarized&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
    <span class="s2">&quot;polarized&quot;</span><span class="p">:</span> <span class="n">SpinMode</span><span class="p">(</span><span class="s2">&quot;polarized&quot;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span>
    <span class="s2">&quot;afm&quot;</span><span class="p">:</span> <span class="n">SpinMode</span><span class="p">(</span><span class="s2">&quot;afm&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span>
    <span class="s2">&quot;spinor&quot;</span><span class="p">:</span> <span class="n">SpinMode</span><span class="p">(</span><span class="s2">&quot;spinor&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">),</span>
    <span class="s2">&quot;spinor_nomag&quot;</span><span class="p">:</span> <span class="n">SpinMode</span><span class="p">(</span><span class="s2">&quot;spinor_nomag&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
<span class="p">}</span>


<div class="viewcode-block" id="Smearing"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.Smearing">[docs]</a><span class="k">class</span> <span class="nc">Smearing</span><span class="p">(</span><span class="n">AbivarAble</span><span class="p">,</span> <span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Variables defining the smearing technique. The preferred way to instanciate</span>
<span class="sd">    a `Smearing` object is via the class method Smearing.as_smearing(string)</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1">#: Mapping string_mode --&gt; occopt</span>
    <span class="n">_mode2occopt</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s1">&#39;nosmearing&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
        <span class="s1">&#39;fermi_dirac&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span>
        <span class="s1">&#39;marzari4&#39;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span>
        <span class="s1">&#39;marzari5&#39;</span><span class="p">:</span> <span class="mi">5</span><span class="p">,</span>
        <span class="s1">&#39;methfessel&#39;</span><span class="p">:</span> <span class="mi">6</span><span class="p">,</span>
        <span class="s1">&#39;gaussian&#39;</span><span class="p">:</span> <span class="mi">7</span><span class="p">}</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">occopt</span><span class="p">,</span> <span class="n">tsmear</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">occopt</span> <span class="o">=</span> <span class="n">occopt</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tsmear</span> <span class="o">=</span> <span class="n">tsmear</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">s</span> <span class="o">=</span> <span class="s2">&quot;occopt </span><span class="si">%d</span><span class="s2"> # </span><span class="si">%s</span><span class="s2"> Smearing</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">occopt</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mode</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">tsmear</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">+=</span> <span class="s1">&#39;tsmear </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">tsmear</span>
        <span class="k">return</span> <span class="n">s</span>

    <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">occopt</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">occopt</span> <span class="ow">and</span>
                <span class="n">np</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tsmear</span><span class="p">,</span> <span class="n">other</span><span class="o">.</span><span class="n">tsmear</span><span class="p">))</span>

    <span class="k">def</span> <span class="fm">__ne__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">return</span> <span class="ow">not</span> <span class="bp">self</span> <span class="o">==</span> <span class="n">other</span>

    <span class="k">def</span> <span class="fm">__bool__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">mode</span> <span class="o">!=</span> <span class="s2">&quot;nosmearing&quot;</span>

    <span class="c1"># py2 old version</span>
    <span class="n">__nonzero__</span> <span class="o">=</span> <span class="fm">__bool__</span>

<div class="viewcode-block" id="Smearing.as_smearing"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.Smearing.as_smearing">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">as_smearing</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructs an instance of `Smearing` from obj. Accepts obj in the form:</span>

<span class="sd">            * Smearing instance</span>
<span class="sd">            * &quot;name:tsmear&quot;  e.g. &quot;gaussian:0.004&quot;  (Hartree units)</span>
<span class="sd">            * &quot;name:tsmear units&quot; e.g. &quot;gaussian:0.1 eV&quot;</span>
<span class="sd">            * None --&gt; no smearing</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">obj</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Smearing</span><span class="o">.</span><span class="n">nosmearing</span><span class="p">()</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="bp">cls</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">obj</span>

        <span class="c1"># obj is a string</span>
        <span class="k">if</span> <span class="n">obj</span> <span class="o">==</span> <span class="s2">&quot;nosmearing&quot;</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">cls</span><span class="o">.</span><span class="n">nosmearing</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">obj</span><span class="p">,</span> <span class="n">tsmear</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;:&quot;</span><span class="p">)</span>
            <span class="n">obj</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>

            <span class="n">occopt</span> <span class="o">=</span> <span class="bp">cls</span><span class="o">.</span><span class="n">_mode2occopt</span><span class="p">[</span><span class="n">obj</span><span class="p">]</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">tsmear</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">tsmear</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
                <span class="n">tsmear</span><span class="p">,</span> <span class="n">unit</span> <span class="o">=</span> <span class="n">tsmear</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tsmear</span> <span class="o">=</span> <span class="n">units</span><span class="o">.</span><span class="n">Energy</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">tsmear</span><span class="p">),</span> <span class="n">unit</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;Ha&quot;</span><span class="p">)</span>

            <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">occopt</span><span class="p">,</span> <span class="n">tsmear</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">mode</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">for</span> <span class="p">(</span><span class="n">mode_str</span><span class="p">,</span> <span class="n">occopt</span><span class="p">)</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_mode2occopt</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">occopt</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">occopt</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">mode_str</span>
        <span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span><span class="s2">&quot;Unknown occopt </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">occopt</span><span class="p">)</span>

<div class="viewcode-block" id="Smearing.nosmearing"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.Smearing.nosmearing">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">nosmearing</span><span class="p">():</span>
        <span class="k">return</span> <span class="n">Smearing</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">)</span></div>

<div class="viewcode-block" id="Smearing.to_abivars"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.Smearing.to_abivars">[docs]</a>    <span class="k">def</span> <span class="nf">to_abivars</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">mode</span> <span class="o">==</span> <span class="s2">&quot;nosmearing&quot;</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;occopt&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;tsmear&quot;</span><span class="p">:</span> <span class="mf">0.0</span><span class="p">}</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;occopt&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">occopt</span><span class="p">,</span> <span class="s2">&quot;tsmear&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">tsmear</span><span class="p">,</span> <span class="p">}</span></div>

<div class="viewcode-block" id="Smearing.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.Smearing.as_dict">[docs]</a>    <span class="nd">@pmg_serialize</span>
    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;json friendly dict representation of Smearing&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;occopt&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">occopt</span><span class="p">,</span> <span class="s2">&quot;tsmear&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">tsmear</span><span class="p">}</span></div>

<div class="viewcode-block" id="Smearing.from_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.Smearing.from_dict">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">Smearing</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;occopt&quot;</span><span class="p">],</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;tsmear&quot;</span><span class="p">])</span></div></div>


<div class="viewcode-block" id="ElectronsAlgorithm"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.ElectronsAlgorithm">[docs]</a><span class="k">class</span> <span class="nc">ElectronsAlgorithm</span><span class="p">(</span><span class="nb">dict</span><span class="p">,</span> <span class="n">AbivarAble</span><span class="p">,</span> <span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Variables controlling the SCF/NSCF algorithm.&quot;&quot;&quot;</span>
    <span class="c1"># None indicates that we use abinit defaults.</span>
    <span class="n">_DEFAULT</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span>
        <span class="n">iprcell</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">iscf</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">diemac</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">diemix</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">diemixmag</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
        <span class="n">dielam</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">diegap</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">dielng</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">diecut</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">nstep</span><span class="o">=</span><span class="mi">50</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">k</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_DEFAULT</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">: No default value has been provided for &quot;</span>
                                 <span class="s2">&quot;key </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="n">k</span><span class="p">))</span>

<div class="viewcode-block" id="ElectronsAlgorithm.to_abivars"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.ElectronsAlgorithm.to_abivars">[docs]</a>    <span class="k">def</span> <span class="nf">to_abivars</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span></div>

<div class="viewcode-block" id="ElectronsAlgorithm.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.ElectronsAlgorithm.as_dict">[docs]</a>    <span class="nd">@pmg_serialize</span>
    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span></div>

<div class="viewcode-block" id="ElectronsAlgorithm.from_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.ElectronsAlgorithm.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="n">d</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">d</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;@module&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">d</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;@class&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="o">**</span><span class="n">d</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="Electrons"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.Electrons">[docs]</a><span class="k">class</span> <span class="nc">Electrons</span><span class="p">(</span><span class="n">AbivarAble</span><span class="p">,</span> <span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;The electronic degrees of freedom&quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">spin_mode</span><span class="o">=</span><span class="s2">&quot;polarized&quot;</span><span class="p">,</span> <span class="n">smearing</span><span class="o">=</span><span class="s2">&quot;fermi_dirac:0.1 eV&quot;</span><span class="p">,</span>
                 <span class="n">algorithm</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">nband</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">fband</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">charge</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">comment</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>  <span class="c1"># occupancies=None,</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructor for Electrons object.</span>

<span class="sd">        Args:</span>
<span class="sd">            comment: String comment for Electrons</span>
<span class="sd">            charge: Total charge of the system. Default is 0.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">comment</span> <span class="o">=</span> <span class="n">comment</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">smearing</span> <span class="o">=</span> <span class="n">Smearing</span><span class="o">.</span><span class="n">as_smearing</span><span class="p">(</span><span class="n">smearing</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">spin_mode</span> <span class="o">=</span> <span class="n">SpinMode</span><span class="o">.</span><span class="n">as_spinmode</span><span class="p">(</span><span class="n">spin_mode</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nband</span> <span class="o">=</span> <span class="n">nband</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">fband</span> <span class="o">=</span> <span class="n">fband</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">charge</span> <span class="o">=</span> <span class="n">charge</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">algorithm</span> <span class="o">=</span> <span class="n">algorithm</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">nsppol</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">spin_mode</span><span class="o">.</span><span class="n">nsppol</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">nspinor</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">spin_mode</span><span class="o">.</span><span class="n">nspinor</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">nspden</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">spin_mode</span><span class="o">.</span><span class="n">nspden</span>

<div class="viewcode-block" id="Electrons.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.Electrons.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="s2">&quot;json friendly dict representation&quot;</span>
        <span class="n">d</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;@module&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;@class&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;spin_mode&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">spin_mode</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;smearing&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">smearing</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;algorithm&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">algorithm</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">algorithm</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;nband&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">nband</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;fband&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fband</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">charge</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;comment&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">comment</span>
        <span class="k">return</span> <span class="n">d</span></div>

<div class="viewcode-block" id="Electrons.from_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.Electrons.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="n">d</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">d</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;@module&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">d</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;@class&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">dec</span> <span class="o">=</span> <span class="n">MontyDecoder</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;spin_mode&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dec</span><span class="o">.</span><span class="n">process_decoded</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;spin_mode&quot;</span><span class="p">])</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;smearing&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dec</span><span class="o">.</span><span class="n">process_decoded</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;smearing&quot;</span><span class="p">])</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;algorithm&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dec</span><span class="o">.</span><span class="n">process_decoded</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;algorithm&quot;</span><span class="p">])</span> <span class="k">if</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;algorithm&quot;</span><span class="p">]</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="o">**</span><span class="n">d</span><span class="p">)</span></div>

<div class="viewcode-block" id="Electrons.to_abivars"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.Electrons.to_abivars">[docs]</a>    <span class="k">def</span> <span class="nf">to_abivars</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">abivars</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">spin_mode</span><span class="o">.</span><span class="n">to_abivars</span><span class="p">()</span>

        <span class="n">abivars</span><span class="o">.</span><span class="n">update</span><span class="p">({</span>
            <span class="s2">&quot;nband&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">nband</span><span class="p">,</span>
            <span class="s2">&quot;fband&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">fband</span><span class="p">,</span>
            <span class="s2">&quot;charge&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">charge</span><span class="p">,</span>
        <span class="p">})</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">smearing</span><span class="p">:</span>
            <span class="n">abivars</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">smearing</span><span class="o">.</span><span class="n">to_abivars</span><span class="p">())</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">algorithm</span><span class="p">:</span>
            <span class="n">abivars</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">algorithm</span><span class="p">)</span>

        <span class="c1"># abivars[&quot;#comment&quot;] = self.comment</span>
        <span class="k">return</span> <span class="n">abivars</span></div></div>


<div class="viewcode-block" id="KSamplingModes"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.KSamplingModes">[docs]</a><span class="k">class</span> <span class="nc">KSamplingModes</span><span class="p">(</span><span class="n">Enum</span><span class="p">):</span>
    <span class="n">monkhorst</span> <span class="o">=</span> <span class="mi">1</span>
    <span class="n">path</span> <span class="o">=</span> <span class="mi">2</span>
    <span class="n">automatic</span> <span class="o">=</span> <span class="mi">3</span></div>


<div class="viewcode-block" id="KSampling"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.KSampling">[docs]</a><span class="k">class</span> <span class="nc">KSampling</span><span class="p">(</span><span class="n">AbivarAble</span><span class="p">,</span> <span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Input variables defining the K-point sampling.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="n">KSamplingModes</span><span class="o">.</span><span class="n">monkhorst</span><span class="p">,</span> <span class="n">num_kpts</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
                 <span class="n">kpts</span><span class="o">=</span><span class="p">((</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),),</span>
                 <span class="n">kpt_shifts</span><span class="o">=</span><span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">),</span>
                 <span class="n">kpts_weights</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">use_symmetries</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">use_time_reversal</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">chksymbreak</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">comment</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Highly flexible constructor for KSampling objects.  The flexibility comes</span>
<span class="sd">        at the cost of usability and in general, it is recommended that you use</span>
<span class="sd">        the default constructor only if you know exactly what you are doing and</span>
<span class="sd">        requires the flexibility.  For most usage cases, the object be constructed</span>
<span class="sd">        far more easily using the convenience static constructors:</span>

<span class="sd">            #. gamma_only</span>
<span class="sd">            #. gamma_centered</span>
<span class="sd">            #. monkhorst</span>
<span class="sd">            #. monkhorst_automatic</span>
<span class="sd">            #. path</span>

<span class="sd">        and it is recommended that you use those.</span>

<span class="sd">        Args:</span>
<span class="sd">            mode: Mode for generating k-poits. Use one of the KSamplingModes enum types.</span>
<span class="sd">            num_kpts: Number of kpoints if mode is &quot;automatic&quot;</span>
<span class="sd">                Number of division for the sampling of the smallest segment if mode is &quot;path&quot;.</span>
<span class="sd">                Not used for the other modes</span>
<span class="sd">            kpts: Number of divisions. Even when only a single specification is</span>
<span class="sd">                  required, e.g. in the automatic scheme, the kpts should still</span>
<span class="sd">                  be specified as a 2D array. e.g., [[20]] or [[2,2,2]].</span>
<span class="sd">            kpt_shifts: Shifts for Kpoints.</span>
<span class="sd">            use_symmetries: False if spatial symmetries should not be used</span>
<span class="sd">                to reduce the number of independent k-points.</span>
<span class="sd">            use_time_reversal: False if time-reversal symmetry should not be used</span>
<span class="sd">                to reduce the number of independent k-points.</span>
<span class="sd">            kpts_weights: Optional weights for kpoints. For explicit kpoints.</span>
<span class="sd">            chksymbreak: Abinit input variable: check whether the BZ sampling preserves the symmetry of the crystal.</span>
<span class="sd">            comment: String comment for Kpoints</span>

<span class="sd">        .. note::</span>
<span class="sd">            The default behavior of the constructor is monkhorst.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">mode</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="n">mode</span> <span class="o">=</span> <span class="n">KSamplingModes</span><span class="p">[</span><span class="n">mode</span><span class="p">]</span>

        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">mode</span> <span class="o">=</span> <span class="n">mode</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">comment</span> <span class="o">=</span> <span class="n">comment</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">num_kpts</span> <span class="o">=</span> <span class="n">num_kpts</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kpts</span> <span class="o">=</span> <span class="n">kpts</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kpt_shifts</span> <span class="o">=</span> <span class="n">kpt_shifts</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kpts_weights</span> <span class="o">=</span> <span class="n">kpts_weights</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">use_symmetries</span> <span class="o">=</span> <span class="n">use_symmetries</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">use_time_reversal</span> <span class="o">=</span> <span class="n">use_time_reversal</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">chksymbreak</span> <span class="o">=</span> <span class="n">chksymbreak</span>

        <span class="n">abivars</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="k">if</span> <span class="n">mode</span> <span class="o">==</span> <span class="n">KSamplingModes</span><span class="o">.</span><span class="n">monkhorst</span><span class="p">:</span>
            <span class="k">assert</span> <span class="n">num_kpts</span> <span class="o">==</span> <span class="mi">0</span>
            <span class="n">ngkpt</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">kpts</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
            <span class="n">shiftk</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">kpt_shifts</span><span class="p">,</span> <span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>

            <span class="k">if</span> <span class="n">use_symmetries</span> <span class="ow">and</span> <span class="n">use_time_reversal</span><span class="p">:</span>
                <span class="n">kptopt</span> <span class="o">=</span> <span class="mi">1</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">use_symmetries</span> <span class="ow">and</span> <span class="n">use_time_reversal</span><span class="p">:</span>
                <span class="n">kptopt</span> <span class="o">=</span> <span class="mi">2</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">use_symmetries</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">use_time_reversal</span><span class="p">:</span>
                <span class="n">kptopt</span> <span class="o">=</span> <span class="mi">3</span>
            <span class="k">if</span> <span class="n">use_symmetries</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">use_time_reversal</span><span class="p">:</span>
                <span class="n">kptopt</span> <span class="o">=</span> <span class="mi">4</span>

            <span class="n">abivars</span><span class="o">.</span><span class="n">update</span><span class="p">({</span>
                <span class="s2">&quot;ngkpt&quot;</span><span class="p">:</span> <span class="n">ngkpt</span><span class="p">,</span>
                <span class="s2">&quot;shiftk&quot;</span><span class="p">:</span> <span class="n">shiftk</span><span class="p">,</span>
                <span class="s2">&quot;nshiftk&quot;</span><span class="p">:</span> <span class="nb">len</span><span class="p">(</span><span class="n">shiftk</span><span class="p">),</span>
                <span class="s2">&quot;kptopt&quot;</span><span class="p">:</span> <span class="n">kptopt</span><span class="p">,</span>
                <span class="s2">&quot;chksymbreak&quot;</span><span class="p">:</span> <span class="n">chksymbreak</span><span class="p">,</span>
            <span class="p">})</span>

        <span class="k">elif</span> <span class="n">mode</span> <span class="o">==</span> <span class="n">KSamplingModes</span><span class="o">.</span><span class="n">path</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">num_kpts</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;For Path mode, num_kpts must be specified and &gt;0&quot;</span><span class="p">)</span>

            <span class="n">kptbounds</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">kpts</span><span class="p">,</span> <span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
            <span class="c1"># print(&quot;in path with kptbound: %s &quot; % kptbounds)</span>

            <span class="n">abivars</span><span class="o">.</span><span class="n">update</span><span class="p">({</span>
                <span class="s2">&quot;ndivsm&quot;</span><span class="p">:</span> <span class="n">num_kpts</span><span class="p">,</span>
                <span class="s2">&quot;kptbounds&quot;</span><span class="p">:</span> <span class="n">kptbounds</span><span class="p">,</span>
                <span class="s2">&quot;kptopt&quot;</span><span class="p">:</span> <span class="o">-</span><span class="nb">len</span><span class="p">(</span><span class="n">kptbounds</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span>
            <span class="p">})</span>

        <span class="k">elif</span> <span class="n">mode</span> <span class="o">==</span> <span class="n">KSamplingModes</span><span class="o">.</span><span class="n">automatic</span><span class="p">:</span>
            <span class="n">kpts</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">kpts</span><span class="p">,</span> <span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">kpts</span><span class="p">)</span> <span class="o">!=</span> <span class="n">num_kpts</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;For Automatic mode, num_kpts must be specified.&quot;</span><span class="p">)</span>

            <span class="n">abivars</span><span class="o">.</span><span class="n">update</span><span class="p">({</span>
                <span class="s2">&quot;kptopt&quot;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
                <span class="s2">&quot;kpt&quot;</span><span class="p">:</span> <span class="n">kpts</span><span class="p">,</span>
                <span class="s2">&quot;nkpt&quot;</span><span class="p">:</span> <span class="n">num_kpts</span><span class="p">,</span>
                <span class="s2">&quot;kptnrm&quot;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="n">num_kpts</span><span class="p">),</span>
                <span class="s2">&quot;wtk&quot;</span><span class="p">:</span> <span class="n">kpts_weights</span><span class="p">,</span>  <span class="c1"># for iscf/=-2, wtk.</span>
                <span class="s2">&quot;chksymbreak&quot;</span><span class="p">:</span> <span class="n">chksymbreak</span><span class="p">,</span>
            <span class="p">})</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Unknown mode </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">mode</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">abivars</span> <span class="o">=</span> <span class="n">abivars</span>
        <span class="c1"># self.abivars[&quot;#comment&quot;] = comment</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">is_homogeneous</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">mode</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;path&quot;</span><span class="p">]</span>

<div class="viewcode-block" id="KSampling.gamma_only"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.KSampling.gamma_only">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">gamma_only</span><span class="p">(</span><span class="bp">cls</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Gamma-only sampling&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">kpt_shifts</span><span class="o">=</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">),</span> <span class="n">comment</span><span class="o">=</span><span class="s2">&quot;Gamma-only sampling&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="KSampling.gamma_centered"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.KSampling.gamma_centered">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">gamma_centered</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">kpts</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">use_symmetries</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">use_time_reversal</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Convenient static constructor for an automatic Gamma centered Kpoint grid.</span>

<span class="sd">        Args:</span>
<span class="sd">            kpts: Subdivisions N_1, N_2 and N_3 along reciprocal lattice vectors.</span>
<span class="sd">            use_symmetries: False if spatial symmetries should not be used</span>
<span class="sd">                to reduce the number of independent k-points.</span>
<span class="sd">            use_time_reversal: False if time-reversal symmetry should not be used</span>
<span class="sd">                to reduce the number of independent k-points.</span>

<span class="sd">        Returns:</span>
<span class="sd">            :class:`KSampling` object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">kpts</span><span class="o">=</span><span class="p">[</span><span class="n">kpts</span><span class="p">],</span> <span class="n">kpt_shifts</span><span class="o">=</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">),</span>
                   <span class="n">use_symmetries</span><span class="o">=</span><span class="n">use_symmetries</span><span class="p">,</span> <span class="n">use_time_reversal</span><span class="o">=</span><span class="n">use_time_reversal</span><span class="p">,</span>
                   <span class="n">comment</span><span class="o">=</span><span class="s2">&quot;gamma-centered mode&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="KSampling.monkhorst"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.KSampling.monkhorst">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">monkhorst</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">ngkpt</span><span class="p">,</span> <span class="n">shiftk</span><span class="o">=</span><span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">),</span> <span class="n">chksymbreak</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">use_symmetries</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                  <span class="n">use_time_reversal</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">comment</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Convenient static constructor for a Monkhorst-Pack mesh.</span>

<span class="sd">        Args:</span>
<span class="sd">            ngkpt: Subdivisions N_1, N_2 and N_3 along reciprocal lattice vectors.</span>
<span class="sd">            shiftk: Shift to be applied to the kpoints.</span>
<span class="sd">            use_symmetries: Use spatial symmetries to reduce the number of k-points.</span>
<span class="sd">            use_time_reversal: Use time-reversal symmetry to reduce the number of k-points.</span>

<span class="sd">        Returns:</span>
<span class="sd">            :class:`KSampling` object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span>
            <span class="n">kpts</span><span class="o">=</span><span class="p">[</span><span class="n">ngkpt</span><span class="p">],</span> <span class="n">kpt_shifts</span><span class="o">=</span><span class="n">shiftk</span><span class="p">,</span>
            <span class="n">use_symmetries</span><span class="o">=</span><span class="n">use_symmetries</span><span class="p">,</span> <span class="n">use_time_reversal</span><span class="o">=</span><span class="n">use_time_reversal</span><span class="p">,</span> <span class="n">chksymbreak</span><span class="o">=</span><span class="n">chksymbreak</span><span class="p">,</span>
            <span class="n">comment</span><span class="o">=</span><span class="n">comment</span> <span class="k">if</span> <span class="n">comment</span> <span class="k">else</span> <span class="s2">&quot;Monkhorst-Pack scheme with user-specified shiftk&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="KSampling.monkhorst_automatic"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.KSampling.monkhorst_automatic">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">monkhorst_automatic</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">ngkpt</span><span class="p">,</span>
                            <span class="n">use_symmetries</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">use_time_reversal</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">chksymbreak</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">comment</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Convenient static constructor for an automatic Monkhorst-Pack mesh.</span>

<span class="sd">        Args:</span>
<span class="sd">            structure: :class:`Structure` object.</span>
<span class="sd">            ngkpt: Subdivisions N_1, N_2 and N_3 along reciprocal lattice vectors.</span>
<span class="sd">            use_symmetries: Use spatial symmetries to reduce the number of k-points.</span>
<span class="sd">            use_time_reversal: Use time-reversal symmetry to reduce the number of k-points.</span>

<span class="sd">        Returns:</span>
<span class="sd">            :class:`KSampling` object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">sg</span> <span class="o">=</span> <span class="n">SpacegroupAnalyzer</span><span class="p">(</span><span class="n">structure</span><span class="p">)</span>
        <span class="c1"># sg.get_crystal_system()</span>
        <span class="c1"># sg.get_point_group_symbol()</span>
        <span class="c1"># TODO</span>
        <span class="n">nshiftk</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="c1"># shiftk = 3*(0.5,) # this is the default</span>
        <span class="n">shiftk</span> <span class="o">=</span> <span class="mi">3</span> <span class="o">*</span> <span class="p">(</span><span class="mf">0.5</span><span class="p">,)</span>

        <span class="c1"># if lattice.ishexagonal:</span>
        <span class="c1"># elif lattice.isbcc</span>
        <span class="c1"># elif lattice.isfcc</span>

        <span class="k">return</span> <span class="bp">cls</span><span class="o">.</span><span class="n">monkhorst</span><span class="p">(</span>
            <span class="n">ngkpt</span><span class="p">,</span> <span class="n">shiftk</span><span class="o">=</span><span class="n">shiftk</span><span class="p">,</span> <span class="n">use_symmetries</span><span class="o">=</span><span class="n">use_symmetries</span><span class="p">,</span> <span class="n">use_time_reversal</span><span class="o">=</span><span class="n">use_time_reversal</span><span class="p">,</span>
            <span class="n">chksymbreak</span><span class="o">=</span><span class="n">chksymbreak</span><span class="p">,</span> <span class="n">comment</span><span class="o">=</span><span class="n">comment</span> <span class="k">if</span> <span class="n">comment</span> <span class="k">else</span> <span class="s2">&quot;Automatic Monkhorst-Pack scheme&quot;</span><span class="p">)</span></div>

    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">_path</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">ndivsm</span><span class="p">,</span> <span class="n">structure</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">kpath_bounds</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">comment</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Static constructor for path in k-space.</span>

<span class="sd">        Args:</span>
<span class="sd">            structure: :class:`Structure` object.</span>
<span class="sd">            kpath_bounds: List with the reduced coordinates of the k-points defining the path.</span>
<span class="sd">            ndivsm: Number of division for the smallest segment.</span>
<span class="sd">            comment: Comment string.</span>

<span class="sd">        Returns:</span>
<span class="sd">            :class:`KSampling` object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">kpath_bounds</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="c1"># Compute the boundaries from the input structure.</span>
            <span class="kn">from</span> <span class="nn">pymatgen.symmetry.bandstructure</span> <span class="kn">import</span> <span class="n">HighSymmKpath</span>
            <span class="n">sp</span> <span class="o">=</span> <span class="n">HighSymmKpath</span><span class="p">(</span><span class="n">structure</span><span class="p">)</span>

            <span class="c1"># Flat the array since &quot;path&quot; is a a list of lists!</span>
            <span class="n">kpath_labels</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">labels</span> <span class="ow">in</span> <span class="n">sp</span><span class="o">.</span><span class="n">kpath</span><span class="p">[</span><span class="s2">&quot;path&quot;</span><span class="p">]:</span>
                <span class="n">kpath_labels</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">labels</span><span class="p">)</span>

            <span class="n">kpath_bounds</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">label</span> <span class="ow">in</span> <span class="n">kpath_labels</span><span class="p">:</span>
                <span class="n">red_coord</span> <span class="o">=</span> <span class="n">sp</span><span class="o">.</span><span class="n">kpath</span><span class="p">[</span><span class="s2">&quot;kpoints&quot;</span><span class="p">][</span><span class="n">label</span><span class="p">]</span>
                <span class="c1"># print(&quot;label %s, red_coord %s&quot; % (label, red_coord))</span>
                <span class="n">kpath_bounds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">red_coord</span><span class="p">)</span>

        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">mode</span><span class="o">=</span><span class="n">KSamplingModes</span><span class="o">.</span><span class="n">path</span><span class="p">,</span> <span class="n">num_kpts</span><span class="o">=</span><span class="n">ndivsm</span><span class="p">,</span> <span class="n">kpts</span><span class="o">=</span><span class="n">kpath_bounds</span><span class="p">,</span>
                   <span class="n">comment</span><span class="o">=</span><span class="n">comment</span> <span class="k">if</span> <span class="n">comment</span> <span class="k">else</span> <span class="s2">&quot;K-Path scheme&quot;</span><span class="p">)</span>

<div class="viewcode-block" id="KSampling.path_from_structure"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.KSampling.path_from_structure">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">path_from_structure</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">ndivsm</span><span class="p">,</span> <span class="n">structure</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;See _path for the meaning of the variables&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="o">.</span><span class="n">_path</span><span class="p">(</span><span class="n">ndivsm</span><span class="p">,</span> <span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">,</span> <span class="n">comment</span><span class="o">=</span><span class="s2">&quot;K-path generated automatically from structure&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="KSampling.explicit_path"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.KSampling.explicit_path">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">explicit_path</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">ndivsm</span><span class="p">,</span> <span class="n">kpath_bounds</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;See _path for the meaning of the variables&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="o">.</span><span class="n">_path</span><span class="p">(</span><span class="n">ndivsm</span><span class="p">,</span> <span class="n">kpath_bounds</span><span class="o">=</span><span class="n">kpath_bounds</span><span class="p">,</span> <span class="n">comment</span><span class="o">=</span><span class="s2">&quot;Explicit K-path&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="KSampling.automatic_density"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.KSampling.automatic_density">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">automatic_density</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">kppa</span><span class="p">,</span> <span class="n">chksymbreak</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">use_symmetries</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">use_time_reversal</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                          <span class="n">shifts</span><span class="o">=</span><span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">)):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns an automatic Kpoint object based on a structure and a kpoint</span>
<span class="sd">        density. Uses Gamma centered meshes for hexagonal cells and Monkhorst-Pack grids otherwise.</span>

<span class="sd">        Algorithm:</span>
<span class="sd">            Uses a simple approach scaling the number of divisions along each</span>
<span class="sd">            reciprocal lattice vector proportional to its length.</span>

<span class="sd">        Args:</span>
<span class="sd">            structure: Input structure</span>
<span class="sd">            kppa: Grid density</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">lattice</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">lattice</span>
        <span class="n">lengths</span> <span class="o">=</span> <span class="n">lattice</span><span class="o">.</span><span class="n">abc</span>
        <span class="n">shifts</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">shifts</span><span class="p">,</span> <span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
        <span class="n">ngrid</span> <span class="o">=</span> <span class="n">kppa</span> <span class="o">/</span> <span class="n">structure</span><span class="o">.</span><span class="n">num_sites</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">shifts</span><span class="p">)</span>

        <span class="n">mult</span> <span class="o">=</span> <span class="p">(</span><span class="n">ngrid</span> <span class="o">*</span> <span class="n">lengths</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">lengths</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">lengths</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="o">**</span> <span class="p">(</span><span class="mi">1</span> <span class="o">/</span> <span class="mf">3.</span><span class="p">)</span>

        <span class="n">num_div</span> <span class="o">=</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="mf">1.0</span> <span class="o">/</span> <span class="n">lengths</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> <span class="n">mult</span><span class="p">))</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">)]</span>
        <span class="c1"># ensure that num_div[i] &gt; 0</span>
        <span class="n">num_div</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="k">if</span> <span class="n">i</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">1</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">num_div</span><span class="p">]</span>

        <span class="n">angles</span> <span class="o">=</span> <span class="n">lattice</span><span class="o">.</span><span class="n">angles</span>
        <span class="n">hex_angle_tol</span> <span class="o">=</span> <span class="mi">5</span>  <span class="c1"># in degrees</span>
        <span class="n">hex_length_tol</span> <span class="o">=</span> <span class="mf">0.01</span>  <span class="c1"># in angstroms</span>

        <span class="n">right_angles</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="k">if</span> <span class="nb">abs</span><span class="p">(</span><span class="n">angles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="mi">90</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">hex_angle_tol</span><span class="p">]</span>

        <span class="n">hex_angles</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
                      <span class="k">if</span> <span class="nb">abs</span><span class="p">(</span><span class="n">angles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="mi">60</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">hex_angle_tol</span> <span class="ow">or</span>
                      <span class="nb">abs</span><span class="p">(</span><span class="n">angles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="mi">120</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">hex_angle_tol</span><span class="p">]</span>

        <span class="n">is_hexagonal</span> <span class="o">=</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">right_angles</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">hex_angles</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span>
                        <span class="ow">and</span> <span class="nb">abs</span><span class="p">(</span><span class="n">lengths</span><span class="p">[</span><span class="n">right_angles</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="o">-</span>
                                <span class="n">lengths</span><span class="p">[</span><span class="n">right_angles</span><span class="p">[</span><span class="mi">1</span><span class="p">]])</span> <span class="o">&lt;</span> <span class="n">hex_length_tol</span><span class="p">)</span>

        <span class="c1"># style = KSamplingModes.gamma</span>
        <span class="c1"># if not is_hexagonal:</span>
        <span class="c1">#    num_div = [i + i % 2 for i in num_div]</span>
        <span class="c1">#    style = KSamplingModes.monkhorst</span>

        <span class="n">comment</span> <span class="o">=</span> <span class="s2">&quot;pymatge.io.abinit generated KPOINTS with grid density = &quot;</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2"> / atom&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">kppa</span><span class="p">)</span>

        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span>
            <span class="n">mode</span><span class="o">=</span><span class="s2">&quot;monkhorst&quot;</span><span class="p">,</span> <span class="n">num_kpts</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">kpts</span><span class="o">=</span><span class="p">[</span><span class="n">num_div</span><span class="p">],</span> <span class="n">kpt_shifts</span><span class="o">=</span><span class="n">shifts</span><span class="p">,</span>
            <span class="n">use_symmetries</span><span class="o">=</span><span class="n">use_symmetries</span><span class="p">,</span> <span class="n">use_time_reversal</span><span class="o">=</span><span class="n">use_time_reversal</span><span class="p">,</span> <span class="n">chksymbreak</span><span class="o">=</span><span class="n">chksymbreak</span><span class="p">,</span>
            <span class="n">comment</span><span class="o">=</span><span class="n">comment</span><span class="p">)</span></div>

<div class="viewcode-block" id="KSampling.to_abivars"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.KSampling.to_abivars">[docs]</a>    <span class="k">def</span> <span class="nf">to_abivars</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">abivars</span></div>

<div class="viewcode-block" id="KSampling.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.KSampling.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">enc</span> <span class="o">=</span> <span class="n">MontyEncoder</span><span class="p">()</span>
        <span class="k">return</span> <span class="p">{</span><span class="s1">&#39;mode&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">mode</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s1">&#39;comment&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">comment</span><span class="p">,</span>
                <span class="s1">&#39;num_kpts&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">num_kpts</span><span class="p">,</span>
                <span class="s1">&#39;kpts&#39;</span><span class="p">:</span> <span class="n">enc</span><span class="o">.</span><span class="n">default</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpts</span><span class="p">)),</span> <span class="s1">&#39;kpt_shifts&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpt_shifts</span><span class="p">,</span>
                <span class="s1">&#39;kpts_weights&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpts_weights</span><span class="p">,</span> <span class="s1">&#39;use_symmetries&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">use_symmetries</span><span class="p">,</span>
                <span class="s1">&#39;use_time_reversal&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">use_time_reversal</span><span class="p">,</span> <span class="s1">&#39;chksymbreak&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">chksymbreak</span><span class="p">,</span>
                <span class="s1">&#39;@module&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span> <span class="s1">&#39;@class&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">}</span></div>

<div class="viewcode-block" id="KSampling.from_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.KSampling.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="n">d</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">d</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;@module&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">d</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;@class&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">dec</span> <span class="o">=</span> <span class="n">MontyDecoder</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s1">&#39;kpts&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dec</span><span class="o">.</span><span class="n">process_decoded</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;kpts&#39;</span><span class="p">])</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="o">**</span><span class="n">d</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="Constraints"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.Constraints">[docs]</a><span class="k">class</span> <span class="nc">Constraints</span><span class="p">(</span><span class="n">AbivarAble</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;This object defines the constraints for structural relaxation&quot;&quot;&quot;</span>

<div class="viewcode-block" id="Constraints.to_abivars"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.Constraints.to_abivars">[docs]</a>    <span class="k">def</span> <span class="nf">to_abivars</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="RelaxationMethod"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.RelaxationMethod">[docs]</a><span class="k">class</span> <span class="nc">RelaxationMethod</span><span class="p">(</span><span class="n">AbivarAble</span><span class="p">,</span> <span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    This object stores the variables for the (constrained) structural optimization</span>
<span class="sd">    ionmov and optcell specify the type of relaxation.</span>
<span class="sd">    The other variables are optional and their use depend on ionmov and optcell.</span>
<span class="sd">    A None value indicates that we use abinit default. Default values can</span>
<span class="sd">    be modified by passing them to the constructor.</span>
<span class="sd">    The set of variables are constructed in to_abivars depending on ionmov and optcell.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">_default_vars</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;ionmov&quot;</span><span class="p">:</span> <span class="n">MANDATORY</span><span class="p">,</span>
        <span class="s2">&quot;optcell&quot;</span><span class="p">:</span> <span class="n">MANDATORY</span><span class="p">,</span>
        <span class="s2">&quot;ntime&quot;</span><span class="p">:</span> <span class="mi">80</span><span class="p">,</span>
        <span class="s2">&quot;dilatmx&quot;</span><span class="p">:</span> <span class="mf">1.05</span><span class="p">,</span>
        <span class="s2">&quot;ecutsm&quot;</span><span class="p">:</span> <span class="mf">0.5</span><span class="p">,</span>
        <span class="s2">&quot;strfact&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
        <span class="s2">&quot;tolmxf&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
        <span class="s2">&quot;strtarget&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
        <span class="s2">&quot;atoms_constraints&quot;</span><span class="p">:</span> <span class="p">{},</span>  <span class="c1"># Constraints are stored in a dictionary. {} means if no constraint is enforced.</span>
    <span class="p">}</span>

    <span class="n">IONMOV_DEFAULT</span> <span class="o">=</span> <span class="mi">3</span>
    <span class="n">OPTCELL_DEFAULT</span> <span class="o">=</span> <span class="mi">2</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>

        <span class="c1"># Initialize abivars with the default values.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">abivars</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_default_vars</span>

        <span class="c1"># Overwrite the keys with the args and kwargs passed to constructor.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">abivars</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">abivars</span> <span class="o">=</span> <span class="n">AttrDict</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">abivars</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">abivars</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">k</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_default_vars</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">: No default value has been provided for key </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="n">k</span><span class="p">))</span>

        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">abivars</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">k</span> <span class="ow">is</span> <span class="n">MANDATORY</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">: No default value has been provided for the mandatory key </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span>
                                 <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="n">k</span><span class="p">))</span>

<div class="viewcode-block" id="RelaxationMethod.atoms_only"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.RelaxationMethod.atoms_only">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">atoms_only</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">atoms_constraints</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">atoms_constraints</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">ionmov</span><span class="o">=</span><span class="bp">cls</span><span class="o">.</span><span class="n">IONMOV_DEFAULT</span><span class="p">,</span> <span class="n">optcell</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">ionmov</span><span class="o">=</span><span class="bp">cls</span><span class="o">.</span><span class="n">IONMOV_DEFAULT</span><span class="p">,</span> <span class="n">optcell</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">atoms_constraints</span><span class="o">=</span><span class="n">atoms_constraints</span><span class="p">)</span></div>

<div class="viewcode-block" id="RelaxationMethod.atoms_and_cell"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.RelaxationMethod.atoms_and_cell">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">atoms_and_cell</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">atoms_constraints</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">atoms_constraints</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">ionmov</span><span class="o">=</span><span class="bp">cls</span><span class="o">.</span><span class="n">IONMOV_DEFAULT</span><span class="p">,</span> <span class="n">optcell</span><span class="o">=</span><span class="bp">cls</span><span class="o">.</span><span class="n">OPTCELL_DEFAULT</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">ionmov</span><span class="o">=</span><span class="bp">cls</span><span class="o">.</span><span class="n">IONMOV_DEFAULT</span><span class="p">,</span> <span class="n">optcell</span><span class="o">=</span><span class="bp">cls</span><span class="o">.</span><span class="n">OPTCELL_DEFAULT</span><span class="p">,</span> <span class="n">atoms_constraints</span><span class="o">=</span><span class="n">atoms_constraints</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">move_atoms</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;True if atoms must be moved.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">abivars</span><span class="o">.</span><span class="n">ionmov</span> <span class="o">!=</span> <span class="mi">0</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">move_cell</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;True if lattice parameters must be optimized.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">abivars</span><span class="o">.</span><span class="n">optcell</span> <span class="o">!=</span> <span class="mi">0</span>

<div class="viewcode-block" id="RelaxationMethod.to_abivars"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.RelaxationMethod.to_abivars">[docs]</a>    <span class="k">def</span> <span class="nf">to_abivars</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Returns a dictionary with the abinit variables&quot;&quot;&quot;</span>
        <span class="c1"># These variables are always present.</span>
        <span class="n">out_vars</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s2">&quot;ionmov&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">abivars</span><span class="o">.</span><span class="n">ionmov</span><span class="p">,</span>
            <span class="s2">&quot;optcell&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">abivars</span><span class="o">.</span><span class="n">optcell</span><span class="p">,</span>
            <span class="s2">&quot;ntime&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">abivars</span><span class="o">.</span><span class="n">ntime</span><span class="p">,</span>
        <span class="p">}</span>

        <span class="c1"># Atom relaxation.</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">move_atoms</span><span class="p">:</span>
            <span class="n">out_vars</span><span class="o">.</span><span class="n">update</span><span class="p">({</span>
                <span class="s2">&quot;tolmxf&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">abivars</span><span class="o">.</span><span class="n">tolmxf</span><span class="p">,</span>
            <span class="p">})</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">abivars</span><span class="o">.</span><span class="n">atoms_constraints</span><span class="p">:</span>
            <span class="c1"># Add input variables for constrained relaxation.</span>
            <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
            <span class="n">out_vars</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">abivars</span><span class="o">.</span><span class="n">atoms_constraints</span><span class="o">.</span><span class="n">to_abivars</span><span class="p">())</span>

        <span class="c1"># Cell relaxation.</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">move_cell</span><span class="p">:</span>
            <span class="n">out_vars</span><span class="o">.</span><span class="n">update</span><span class="p">({</span>
                <span class="s2">&quot;dilatmx&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">abivars</span><span class="o">.</span><span class="n">dilatmx</span><span class="p">,</span>
                <span class="s2">&quot;ecutsm&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">abivars</span><span class="o">.</span><span class="n">ecutsm</span><span class="p">,</span>
                <span class="s2">&quot;strfact&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">abivars</span><span class="o">.</span><span class="n">strfact</span><span class="p">,</span>
                <span class="s2">&quot;strtarget&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">abivars</span><span class="o">.</span><span class="n">strtarget</span><span class="p">,</span>
            <span class="p">})</span>

        <span class="k">return</span> <span class="n">out_vars</span></div>

<div class="viewcode-block" id="RelaxationMethod.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.RelaxationMethod.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">d</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_default_vars</span><span class="p">)</span>
        <span class="n">d</span><span class="p">[</span><span class="s1">&#39;@module&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span>
        <span class="n">d</span><span class="p">[</span><span class="s1">&#39;@class&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
        <span class="k">return</span> <span class="n">d</span></div>

<div class="viewcode-block" id="RelaxationMethod.from_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.RelaxationMethod.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="n">d</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">d</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;@module&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">d</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;@class&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="o">**</span><span class="n">d</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="PPModelModes"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.PPModelModes">[docs]</a><span class="k">class</span> <span class="nc">PPModelModes</span><span class="p">(</span><span class="n">Enum</span><span class="p">):</span>
    <span class="n">noppmodel</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">godby</span> <span class="o">=</span> <span class="mi">1</span>
    <span class="n">hybersten</span> <span class="o">=</span> <span class="mi">2</span>
    <span class="n">linden</span> <span class="o">=</span> <span class="mi">3</span>
    <span class="n">farid</span> <span class="o">=</span> <span class="mi">4</span></div>


<div class="viewcode-block" id="PPModel"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.PPModel">[docs]</a><span class="k">class</span> <span class="nc">PPModel</span><span class="p">(</span><span class="n">AbivarAble</span><span class="p">,</span> <span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Parameters defining the plasmon-pole technique.</span>
<span class="sd">    The common way to instanciate a PPModel object is via the class method PPModel.as_ppmodel(string)</span>
<span class="sd">    &quot;&quot;&quot;</span>

<div class="viewcode-block" id="PPModel.as_ppmodel"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.PPModel.as_ppmodel">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">as_ppmodel</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructs an instance of PPModel from obj.</span>

<span class="sd">        Accepts obj in the form:</span>
<span class="sd">            * PPmodel instance</span>
<span class="sd">            * string. e.g &quot;godby:12.3 eV&quot;, &quot;linden&quot;.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="bp">cls</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">obj</span>

        <span class="c1"># obj is a string</span>
        <span class="k">if</span> <span class="s2">&quot;:&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">obj</span><span class="p">:</span>
            <span class="n">mode</span><span class="p">,</span> <span class="n">plasmon_freq</span> <span class="o">=</span> <span class="n">obj</span><span class="p">,</span> <span class="kc">None</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># Extract mode and plasmon_freq</span>
            <span class="n">mode</span><span class="p">,</span> <span class="n">plasmon_freq</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;:&quot;</span><span class="p">)</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">plasmon_freq</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">plasmon_freq</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
                <span class="n">plasmon_freq</span><span class="p">,</span> <span class="n">unit</span> <span class="o">=</span> <span class="n">plasmon_freq</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">plasmon_freq</span> <span class="o">=</span> <span class="n">units</span><span class="o">.</span><span class="n">Energy</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">plasmon_freq</span><span class="p">),</span> <span class="n">unit</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;Ha&quot;</span><span class="p">)</span>

        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">mode</span><span class="o">=</span><span class="n">mode</span><span class="p">,</span> <span class="n">plasmon_freq</span><span class="o">=</span><span class="n">plasmon_freq</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s2">&quot;godby&quot;</span><span class="p">,</span> <span class="n">plasmon_freq</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">mode</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="n">mode</span> <span class="o">=</span> <span class="n">PPModelModes</span><span class="p">[</span><span class="n">mode</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mode</span> <span class="o">=</span> <span class="n">mode</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">plasmon_freq</span> <span class="o">=</span> <span class="n">plasmon_freq</span>

    <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">other</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">mode</span> <span class="o">!=</span> <span class="n">other</span><span class="o">.</span><span class="n">mode</span><span class="p">:</span>
                <span class="k">return</span> <span class="kc">False</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">plasmon_freq</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">other</span><span class="o">.</span><span class="n">plasmon_freq</span> <span class="ow">is</span> <span class="kc">None</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">plasmon_freq</span><span class="p">,</span> <span class="n">other</span><span class="o">.</span><span class="n">plasmon_freq</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__ne__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">return</span> <span class="ow">not</span> <span class="bp">self</span> <span class="o">==</span> <span class="n">other</span>

    <span class="k">def</span> <span class="fm">__bool__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">mode</span> <span class="o">!=</span> <span class="n">PPModelModes</span><span class="o">.</span><span class="n">noppmodel</span>

    <span class="c1"># py2 old version</span>
    <span class="n">__nonzero__</span> <span class="o">=</span> <span class="fm">__bool__</span>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s2">&quot;&lt;</span><span class="si">%s</span><span class="s2"> at </span><span class="si">%s</span><span class="s2">, mode = </span><span class="si">%s</span><span class="s2">&gt;&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="nb">id</span><span class="p">(</span><span class="bp">self</span><span class="p">),</span>
                                          <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mode</span><span class="p">))</span>

<div class="viewcode-block" id="PPModel.to_abivars"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.PPModel.to_abivars">[docs]</a>    <span class="k">def</span> <span class="nf">to_abivars</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;ppmodel&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">mode</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                    <span class="s2">&quot;ppmfrq&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">plasmon_freq</span><span class="p">}</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">{}</span></div>

<div class="viewcode-block" id="PPModel.get_noppmodel"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.PPModel.get_noppmodel">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">get_noppmodel</span><span class="p">(</span><span class="bp">cls</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">mode</span><span class="o">=</span><span class="s2">&quot;noppmodel&quot;</span><span class="p">,</span> <span class="n">plasmon_freq</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span></div>

<div class="viewcode-block" id="PPModel.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.PPModel.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;mode&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">mode</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s2">&quot;plasmon_freq&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">plasmon_freq</span><span class="p">,</span>
                <span class="s2">&quot;@module&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span>
                <span class="s2">&quot;@class&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">}</span></div>

<div class="viewcode-block" id="PPModel.from_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.PPModel.from_dict">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">PPModel</span><span class="p">(</span><span class="n">mode</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;mode&quot;</span><span class="p">],</span> <span class="n">plasmon_freq</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;plasmon_freq&quot;</span><span class="p">])</span></div></div>


<div class="viewcode-block" id="HilbertTransform"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.HilbertTransform">[docs]</a><span class="k">class</span> <span class="nc">HilbertTransform</span><span class="p">(</span><span class="n">AbivarAble</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Parameters for the Hilbert-transform method (Screening code)</span>
<span class="sd">    i.e. the parameters defining the frequency mesh used for the spectral function</span>
<span class="sd">    and the frequency mesh used for the polarizability</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">nomegasf</span><span class="p">,</span> <span class="n">domegasf</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">spmeth</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">nfreqre</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">freqremax</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">nfreqim</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">freqremin</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            nomegasf: Number of points for sampling the spectral function along the real axis.</span>
<span class="sd">            domegasf: Step in Ha for the linear mesh used for the spectral function.</span>
<span class="sd">            spmeth: Algorith for the representation of the delta function.</span>
<span class="sd">            nfreqre: Number of points along the real axis (linear mesh).</span>
<span class="sd">            freqremax: Maximum frequency for W along the real axis (in hartree).</span>
<span class="sd">            nfreqim: Number of point along the imaginary axis (Gauss-Legendre mesh).</span>
<span class="sd">            freqremin: Minimum frequency for W along the real axis (in hartree).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Spectral function</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nomegasf</span> <span class="o">=</span> <span class="n">nomegasf</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">domegasf</span> <span class="o">=</span> <span class="n">domegasf</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">spmeth</span> <span class="o">=</span> <span class="n">spmeth</span>

        <span class="c1"># Mesh for the contour-deformation method used for the integration of the self-energy</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nfreqre</span> <span class="o">=</span> <span class="n">nfreqre</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">freqremax</span> <span class="o">=</span> <span class="n">freqremax</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">freqremin</span> <span class="o">=</span> <span class="n">freqremin</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nfreqim</span> <span class="o">=</span> <span class="n">nfreqim</span>

<div class="viewcode-block" id="HilbertTransform.to_abivars"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.HilbertTransform.to_abivars">[docs]</a>    <span class="k">def</span> <span class="nf">to_abivars</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Returns a dictionary with the abinit variables&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">{</span>
            <span class="c1"># Spectral function</span>
            <span class="s2">&quot;nomegasf&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">nomegasf</span><span class="p">,</span>
            <span class="s2">&quot;domegasf&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">domegasf</span><span class="p">,</span>
            <span class="s2">&quot;spmeth&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">spmeth</span><span class="p">,</span>
            <span class="c1"># Frequency mesh for the polarizability</span>
            <span class="s2">&quot;nfreqre&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">nfreqre</span><span class="p">,</span>
            <span class="s2">&quot;freqremax&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">freqremax</span><span class="p">,</span>
            <span class="s2">&quot;nfreqim&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">nfreqim</span><span class="p">,</span>
            <span class="s2">&quot;freqremin&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">freqremin</span><span class="p">,</span>
        <span class="p">}</span></div></div>


<div class="viewcode-block" id="ModelDielectricFunction"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.ModelDielectricFunction">[docs]</a><span class="k">class</span> <span class="nc">ModelDielectricFunction</span><span class="p">(</span><span class="n">AbivarAble</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Model dielectric function used for BSE calculation&quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mdf_epsinf</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mdf_epsinf</span> <span class="o">=</span> <span class="n">mdf_epsinf</span>

<div class="viewcode-block" id="ModelDielectricFunction.to_abivars"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.ModelDielectricFunction.to_abivars">[docs]</a>    <span class="k">def</span> <span class="nf">to_abivars</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;mdf_epsinf&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">mdf_epsinf</span><span class="p">}</span></div></div>


<span class="c1">##########################################################################################</span>
<span class="c1"># WORK IN PROGRESS ######################################</span>
<span class="c1">##########################################################################################</span>


<div class="viewcode-block" id="Screening"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.Screening">[docs]</a><span class="k">class</span> <span class="nc">Screening</span><span class="p">(</span><span class="n">AbivarAble</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    This object defines the parameters used for the</span>
<span class="sd">    computation of the screening function.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># Approximations used for W</span>
    <span class="n">_WTYPES</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;RPA&quot;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
    <span class="p">}</span>

    <span class="c1"># Self-consistecy modes</span>
    <span class="n">_SC_MODES</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;one_shot&quot;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
        <span class="s2">&quot;energy_only&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
        <span class="s2">&quot;wavefunctions&quot;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span>
    <span class="p">}</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ecuteps</span><span class="p">,</span> <span class="n">nband</span><span class="p">,</span> <span class="n">w_type</span><span class="o">=</span><span class="s2">&quot;RPA&quot;</span><span class="p">,</span> <span class="n">sc_mode</span><span class="o">=</span><span class="s2">&quot;one_shot&quot;</span><span class="p">,</span>
                 <span class="n">hilbert</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">ecutwfn</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">inclvkb</span><span class="o">=</span><span class="mi">2</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            ecuteps: Cutoff energy for the screening (Ha units).</span>
<span class="sd">            nband Number of bands for the Green&#39;s function</span>
<span class="sd">            w_type: Screening type</span>
<span class="sd">            sc_mode: Self-consistency mode.</span>
<span class="sd">            hilbert: Instance of :class:`HilbertTransform` defining the parameters for the Hilber transform method.</span>
<span class="sd">            ecutwfn: Cutoff energy for the wavefunctions (Default: ecutwfn == ecut).</span>
<span class="sd">            inclvkb: Option for the treatment of the dipole matrix elements (NC pseudos).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">w_type</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_WTYPES</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;W_TYPE: </span><span class="si">%s</span><span class="s2"> is not supported&quot;</span> <span class="o">%</span> <span class="n">w_type</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">sc_mode</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_SC_MODES</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Self-consistecy mode </span><span class="si">%s</span><span class="s2"> is not supported&quot;</span> <span class="o">%</span> <span class="n">sc_mode</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">ecuteps</span> <span class="o">=</span> <span class="n">ecuteps</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nband</span> <span class="o">=</span> <span class="n">nband</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">w_type</span> <span class="o">=</span> <span class="n">w_type</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sc_mode</span> <span class="o">=</span> <span class="n">sc_mode</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">ecutwfn</span> <span class="o">=</span> <span class="n">ecutwfn</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">inclvkb</span> <span class="o">=</span> <span class="n">inclvkb</span>

        <span class="k">if</span> <span class="n">hilbert</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">&quot;Hilber transform not coded yet&quot;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">hilbert</span> <span class="o">=</span> <span class="n">hilbert</span>

        <span class="c1"># Default values (equivalent to those used in Abinit8)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">gwpara</span> <span class="o">=</span> <span class="mi">2</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">awtr</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">symchi</span> <span class="o">=</span> <span class="mi">1</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">optdriver</span> <span class="o">=</span> <span class="mi">3</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">use_hilbert</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s2">&quot;hilbert&quot;</span><span class="p">)</span>

    <span class="c1"># @property</span>
    <span class="c1"># def gwcalctyp(self):</span>
    <span class="c1">#    &quot;Return the value of the gwcalctyp input variable&quot;</span>
    <span class="c1">#    dig0 = str(self._SIGMA_TYPES[self.type])</span>
    <span class="c1">#    dig1 = str(self._SC_MODES[self.sc_mode]</span>
    <span class="c1">#    return dig1.strip() + dig0.strip()</span>

<div class="viewcode-block" id="Screening.to_abivars"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.Screening.to_abivars">[docs]</a>    <span class="k">def</span> <span class="nf">to_abivars</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Returns a dictionary with the abinit variables&quot;&quot;&quot;</span>
        <span class="n">abivars</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s2">&quot;ecuteps&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">ecuteps</span><span class="p">,</span>
            <span class="s2">&quot;ecutwfn&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">ecutwfn</span><span class="p">,</span>
            <span class="s2">&quot;inclvkb&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">inclvkb</span><span class="p">,</span>
            <span class="s2">&quot;gwpara&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">gwpara</span><span class="p">,</span>
            <span class="s2">&quot;awtr&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">awtr</span><span class="p">,</span>
            <span class="s2">&quot;symchi&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">symchi</span><span class="p">,</span>
            <span class="s2">&quot;nband&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">nband</span><span class="p">,</span>
            <span class="c1"># &quot;gwcalctyp&quot;: self.gwcalctyp,</span>
            <span class="c1"># &quot;fftgw&quot;    : self.fftgw,</span>
            <span class="s2">&quot;optdriver&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">optdriver</span><span class="p">,</span>
        <span class="p">}</span>

        <span class="c1"># Variables for the Hilber transform.</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">use_hilbert</span><span class="p">:</span>
            <span class="n">abivars</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">hilbert</span><span class="o">.</span><span class="n">to_abivars</span><span class="p">())</span>

        <span class="k">return</span> <span class="n">abivars</span></div></div>


<div class="viewcode-block" id="SelfEnergy"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.SelfEnergy">[docs]</a><span class="k">class</span> <span class="nc">SelfEnergy</span><span class="p">(</span><span class="n">AbivarAble</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    This object defines the parameters used for the computation of the self-energy.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">_SIGMA_TYPES</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;gw&quot;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
        <span class="s2">&quot;hartree_fock&quot;</span><span class="p">:</span> <span class="mi">5</span><span class="p">,</span>
        <span class="s2">&quot;sex&quot;</span><span class="p">:</span> <span class="mi">6</span><span class="p">,</span>
        <span class="s2">&quot;cohsex&quot;</span><span class="p">:</span> <span class="mi">7</span><span class="p">,</span>
        <span class="s2">&quot;model_gw_ppm&quot;</span><span class="p">:</span> <span class="mi">8</span><span class="p">,</span>
        <span class="s2">&quot;model_gw_cd&quot;</span><span class="p">:</span> <span class="mi">9</span><span class="p">,</span>
    <span class="p">}</span>

    <span class="n">_SC_MODES</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;one_shot&quot;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
        <span class="s2">&quot;energy_only&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
        <span class="s2">&quot;wavefunctions&quot;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span>
    <span class="p">}</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">se_type</span><span class="p">,</span> <span class="n">sc_mode</span><span class="p">,</span> <span class="n">nband</span><span class="p">,</span> <span class="n">ecutsigx</span><span class="p">,</span> <span class="n">screening</span><span class="p">,</span>
                 <span class="n">gw_qprange</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">ppmodel</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">ecuteps</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">ecutwfn</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">gwpara</span><span class="o">=</span><span class="mi">2</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            se_type: Type of self-energy (str)</span>
<span class="sd">            sc_mode: Self-consistency mode.</span>
<span class="sd">            nband: Number of bands for the Green&#39;s function</span>
<span class="sd">            ecutsigx: Cutoff energy for the exchange part of the self-energy (Ha units).</span>
<span class="sd">            screening: :class:`Screening` instance.</span>
<span class="sd">            gw_qprange: Option for the automatic selection of k-points and bands for GW corrections.</span>
<span class="sd">                See Abinit docs for more detail. The default value makes the code computie the</span>
<span class="sd">                QP energies for all the point in the IBZ and one band above and one band below the Fermi level.</span>
<span class="sd">            ppmodel: :class:`PPModel` instance with the parameters used for the plasmon-pole technique.</span>
<span class="sd">            ecuteps: Cutoff energy for the screening (Ha units).</span>
<span class="sd">            ecutwfn: Cutoff energy for the wavefunctions (Default: ecutwfn == ecut).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">se_type</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_SIGMA_TYPES</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;SIGMA_TYPE: </span><span class="si">%s</span><span class="s2"> is not supported&quot;</span> <span class="o">%</span> <span class="n">se_type</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">sc_mode</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_SC_MODES</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Self-consistecy mode </span><span class="si">%s</span><span class="s2"> is not supported&quot;</span> <span class="o">%</span> <span class="n">sc_mode</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">se_type</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sc_mode</span> <span class="o">=</span> <span class="n">sc_mode</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nband</span> <span class="o">=</span> <span class="n">nband</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ecutsigx</span> <span class="o">=</span> <span class="n">ecutsigx</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">screening</span> <span class="o">=</span> <span class="n">screening</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">gw_qprange</span> <span class="o">=</span> <span class="n">gw_qprange</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">gwpara</span> <span class="o">=</span> <span class="n">gwpara</span>

        <span class="k">if</span> <span class="n">ppmodel</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">assert</span> <span class="ow">not</span> <span class="n">screening</span><span class="o">.</span><span class="n">use_hilbert</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ppmodel</span> <span class="o">=</span> <span class="n">PPModel</span><span class="o">.</span><span class="n">as_ppmodel</span><span class="p">(</span><span class="n">ppmodel</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">ecuteps</span> <span class="o">=</span> <span class="n">ecuteps</span> <span class="k">if</span> <span class="n">ecuteps</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">screening</span><span class="o">.</span><span class="n">ecuteps</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ecutwfn</span> <span class="o">=</span> <span class="n">ecutwfn</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">optdriver</span> <span class="o">=</span> <span class="mi">4</span>

        <span class="c1"># band_mode in [&quot;gap&quot;, &quot;full&quot;]</span>

        <span class="c1"># if isinstance(kptgw, str) and kptgw == &quot;all&quot;:</span>
        <span class="c1">#    self.kptgw = None</span>
        <span class="c1">#    self.nkptgw = None</span>
        <span class="c1"># else:</span>
        <span class="c1">#    self.kptgw = np.reshape(kptgw, (-1,3))</span>
        <span class="c1">#    self.nkptgw =  len(self.kptgw)</span>

        <span class="c1"># if bdgw is None:</span>
        <span class="c1">#    raise ValueError(&quot;bdgw must be specified&quot;)</span>

        <span class="c1"># if isinstance(bdgw, str):</span>
        <span class="c1">#    # TODO add new variable in Abinit so that we can specify</span>
        <span class="c1">#    # an energy interval around the KS gap.</span>
        <span class="c1">#    homo = float(nele) / 2.0</span>
        <span class="c1">#    #self.bdgw =</span>

        <span class="c1"># else:</span>
        <span class="c1">#    self.bdgw = np.reshape(bdgw, (-1,2))</span>

        <span class="c1"># self.freq_int = freq_int</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">use_ppmodel</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;True if we are using the plasmon-pole approximation.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s2">&quot;ppmodel&quot;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">gwcalctyp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Returns the value of the gwcalctyp input variable.&quot;&quot;&quot;</span>
        <span class="n">dig0</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_SIGMA_TYPES</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">type</span><span class="p">])</span>
        <span class="n">dig1</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_SC_MODES</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">sc_mode</span><span class="p">])</span>
        <span class="k">return</span> <span class="n">dig1</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="o">+</span> <span class="n">dig0</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">symsigma</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;1 if symmetries can be used to reduce the number of q-points.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="mi">1</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sc_mode</span> <span class="o">==</span> <span class="s2">&quot;one_shot&quot;</span> <span class="k">else</span> <span class="mi">0</span>

<div class="viewcode-block" id="SelfEnergy.to_abivars"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.SelfEnergy.to_abivars">[docs]</a>    <span class="k">def</span> <span class="nf">to_abivars</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Returns a dictionary with the abinit variables.&quot;&quot;&quot;</span>
        <span class="n">abivars</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span>
            <span class="n">gwcalctyp</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">gwcalctyp</span><span class="p">,</span>
            <span class="n">ecuteps</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">ecuteps</span><span class="p">,</span>
            <span class="n">ecutsigx</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">ecutsigx</span><span class="p">,</span>
            <span class="n">symsigma</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">symsigma</span><span class="p">,</span>
            <span class="n">gw_qprange</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">gw_qprange</span><span class="p">,</span>
            <span class="n">gwpara</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">gwpara</span><span class="p">,</span>
            <span class="n">optdriver</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">optdriver</span><span class="p">,</span>
            <span class="n">nband</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">nband</span>
            <span class="c1"># &quot;ecutwfn&quot;  : self.ecutwfn,</span>
            <span class="c1"># &quot;kptgw&quot;    : self.kptgw,</span>
            <span class="c1"># &quot;nkptgw&quot;   : self.nkptgw,</span>
            <span class="c1"># &quot;bdgw&quot;     : self.bdgw,</span>
        <span class="p">)</span>

        <span class="c1"># FIXME: problem with the spin</span>
        <span class="c1"># assert len(self.bdgw) == self.nkptgw</span>

        <span class="c1"># ppmodel variables</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">use_ppmodel</span><span class="p">:</span>
            <span class="n">abivars</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ppmodel</span><span class="o">.</span><span class="n">to_abivars</span><span class="p">())</span>

        <span class="k">return</span> <span class="n">abivars</span></div></div>


<div class="viewcode-block" id="ExcHamiltonian"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.ExcHamiltonian">[docs]</a><span class="k">class</span> <span class="nc">ExcHamiltonian</span><span class="p">(</span><span class="n">AbivarAble</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;This object contains the parameters for the solution of the Bethe-Salpeter equation.&quot;&quot;&quot;</span>
    <span class="c1"># Types of excitonic Hamiltonian.</span>
    <span class="n">_EXC_TYPES</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;TDA&quot;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>  <span class="c1"># Tamm-Dancoff approximation.</span>
        <span class="s2">&quot;coupling&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>  <span class="c1"># Calculation with coupling.</span>
    <span class="p">}</span>

    <span class="c1"># Algorithms used to compute the macroscopic dielectric function</span>
    <span class="c1"># and/or the exciton wavefunctions.</span>
    <span class="n">_ALGO2VAR</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;direct_diago&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
        <span class="s2">&quot;haydock&quot;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span>
        <span class="s2">&quot;cg&quot;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span>
    <span class="p">}</span>

    <span class="c1"># Options specifying the treatment of the Coulomb term.</span>
    <span class="n">_COULOMB_MODES</span> <span class="o">=</span> <span class="p">[</span>
        <span class="s2">&quot;diago&quot;</span><span class="p">,</span>
        <span class="s2">&quot;full&quot;</span><span class="p">,</span>
        <span class="s2">&quot;model_df&quot;</span>
    <span class="p">]</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bs_loband</span><span class="p">,</span> <span class="n">nband</span><span class="p">,</span> <span class="n">mbpt_sciss</span><span class="p">,</span> <span class="n">coulomb_mode</span><span class="p">,</span> <span class="n">ecuteps</span><span class="p">,</span> <span class="n">spin_mode</span><span class="o">=</span><span class="s2">&quot;polarized&quot;</span><span class="p">,</span> <span class="n">mdf_epsinf</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">exc_type</span><span class="o">=</span><span class="s2">&quot;TDA&quot;</span><span class="p">,</span> <span class="n">algo</span><span class="o">=</span><span class="s2">&quot;haydock&quot;</span><span class="p">,</span> <span class="n">with_lf</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">bs_freq_mesh</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">zcut</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            bs_loband: Lowest band index (Fortran convention) used in the e-h  basis set.</span>
<span class="sd">                Can be scalar or array of shape (nsppol,). Must be &gt;= 1 and &lt;= nband</span>
<span class="sd">            nband: Max band index used in the e-h  basis set.</span>
<span class="sd">            mbpt_sciss: Scissors energy in Hartree.</span>
<span class="sd">            coulomb_mode: Treatment of the Coulomb term.</span>
<span class="sd">            ecuteps: Cutoff energy for W in Hartree.</span>
<span class="sd">            mdf_epsinf: Macroscopic dielectric function :math:`\\epsilon_\\inf` used in</span>
<span class="sd">                the model dielectric function.</span>
<span class="sd">            exc_type: Approximation used for the BSE Hamiltonian</span>
<span class="sd">            with_lf: True if local field effects are included &lt;==&gt; exchange term is included</span>
<span class="sd">            bs_freq_mesh: Frequency mesh for the macroscopic dielectric function (start, stop, step) in Ha.</span>
<span class="sd">            zcut: Broadening parameter in Ha.</span>
<span class="sd">            **kwargs:</span>
<span class="sd">                Extra keywords</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">spin_mode</span> <span class="o">=</span> <span class="n">SpinMode</span><span class="o">.</span><span class="n">as_spinmode</span><span class="p">(</span><span class="n">spin_mode</span><span class="p">)</span>

        <span class="c1"># We want an array bs_loband(nsppol).</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">bs_loband</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">bs_loband</span><span class="p">,</span> <span class="n">spin_mode</span><span class="o">.</span><span class="n">nsppol</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
            <span class="n">bs_loband</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">spin_mode</span><span class="o">.</span><span class="n">nsppol</span> <span class="o">*</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">bs_loband</span><span class="p">)])</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">bs_loband</span> <span class="o">=</span> <span class="n">bs_loband</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nband</span> <span class="o">=</span> <span class="n">nband</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mbpt_sciss</span> <span class="o">=</span> <span class="n">mbpt_sciss</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">coulomb_mode</span> <span class="o">=</span> <span class="n">coulomb_mode</span>
        <span class="k">assert</span> <span class="n">coulomb_mode</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_COULOMB_MODES</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ecuteps</span> <span class="o">=</span> <span class="n">ecuteps</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">mdf_epsinf</span> <span class="o">=</span> <span class="n">mdf_epsinf</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">exc_type</span> <span class="o">=</span> <span class="n">exc_type</span>
        <span class="k">assert</span> <span class="n">exc_type</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_EXC_TYPES</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">algo</span> <span class="o">=</span> <span class="n">algo</span>
        <span class="k">assert</span> <span class="n">algo</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ALGO2VAR</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">with_lf</span> <span class="o">=</span> <span class="n">with_lf</span>

        <span class="c1"># if bs_freq_mesh is not given, abinit will select its own mesh.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bs_freq_mesh</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">bs_freq_mesh</span><span class="p">)</span> <span class="k">if</span> <span class="n">bs_freq_mesh</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">bs_freq_mesh</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">zcut</span> <span class="o">=</span> <span class="n">zcut</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">optdriver</span> <span class="o">=</span> <span class="mi">99</span>

        <span class="c1"># Extra options.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span> <span class="o">=</span> <span class="n">kwargs</span>
        <span class="c1"># if &quot;chksymbreak&quot; not in self.kwargs:</span>
        <span class="c1">#    self.kwargs[&quot;chksymbreak&quot;] = 0</span>

        <span class="c1"># Consistency check</span>
        <span class="k">if</span> <span class="nb">any</span><span class="p">(</span><span class="n">bs_loband</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;bs_loband &lt;= 0 while it is </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">bs_loband</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">any</span><span class="p">(</span><span class="n">bs_loband</span> <span class="o">&gt;=</span> <span class="n">nband</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;bs_loband (</span><span class="si">%s</span><span class="s2">) &gt;= nband (</span><span class="si">%s</span><span class="s2">)&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">bs_loband</span><span class="p">,</span> <span class="n">nband</span><span class="p">))</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">inclvkb</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Treatment of the dipole matrix element (NC pseudos, default is 2)&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;inclvkb&quot;</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">use_haydock</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;True if we are using the Haydock iterative technique.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">algo</span> <span class="o">==</span> <span class="s2">&quot;haydock&quot;</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">use_cg</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;True if we are using the conjugate gradient method.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">algo</span> <span class="o">==</span> <span class="s2">&quot;cg&quot;</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">use_direct_diago</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;True if we are performing the direct diagonalization of the BSE Hamiltonian.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">algo</span> <span class="o">==</span> <span class="s2">&quot;direct_diago&quot;</span>

<div class="viewcode-block" id="ExcHamiltonian.to_abivars"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.abiobjects.html#pymatgen.io.abinit.abiobjects.ExcHamiltonian.to_abivars">[docs]</a>    <span class="k">def</span> <span class="nf">to_abivars</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Returns a dictionary with the abinit variables.&quot;&quot;&quot;</span>
        <span class="n">abivars</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span>
            <span class="n">bs_calctype</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
            <span class="n">bs_loband</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">bs_loband</span><span class="p">,</span>
            <span class="c1"># nband=self.nband,</span>
            <span class="n">mbpt_sciss</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">mbpt_sciss</span><span class="p">,</span>
            <span class="n">ecuteps</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">ecuteps</span><span class="p">,</span>
            <span class="n">bs_algorithm</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_ALGO2VAR</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">algo</span><span class="p">],</span>
            <span class="n">bs_coulomb_term</span><span class="o">=</span><span class="mi">21</span><span class="p">,</span>
            <span class="n">mdf_epsinf</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">mdf_epsinf</span><span class="p">,</span>
            <span class="n">bs_exchange_term</span><span class="o">=</span><span class="mi">1</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">with_lf</span> <span class="k">else</span> <span class="mi">0</span><span class="p">,</span>
            <span class="n">inclvkb</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">inclvkb</span><span class="p">,</span>
            <span class="n">zcut</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">zcut</span><span class="p">,</span>
            <span class="n">bs_freq_mesh</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">bs_freq_mesh</span><span class="p">,</span>
            <span class="n">bs_coupling</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_EXC_TYPES</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">exc_type</span><span class="p">],</span>
            <span class="n">optdriver</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">optdriver</span><span class="p">,</span>
        <span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">use_haydock</span><span class="p">:</span>
            <span class="c1"># FIXME</span>
            <span class="n">abivars</span><span class="o">.</span><span class="n">update</span><span class="p">(</span>
                <span class="n">bs_haydock_niter</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>  <span class="c1"># No. of iterations for Haydock</span>
                <span class="n">bs_hayd_term</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>  <span class="c1"># No terminator</span>
                <span class="n">bs_haydock_tol</span><span class="o">=</span><span class="p">[</span><span class="mf">0.05</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>  <span class="c1"># Stopping criteria</span>
            <span class="p">)</span>

        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">use_direct_diago</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">)</span>

        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">use_cg</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Unknown algorithm for EXC: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">algo</span><span class="p">)</span>

        <span class="c1"># Add extra kwargs</span>
        <span class="n">abivars</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">abivars</span></div></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.io.abinit.abiobjects</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>